package list

import (
	"sync"
)

type PidList struct {
	Pids map[int]string
	Lock sync.Mutex
}

func NewPidList() (l PidList) {
	l.Pids = make(map[int]string)
	return
}

func (p *PidList) Add(pid int, name string) {
	if _, ok := p.Pids[pid]; ok {
		return
	}
	p.Pids[pid] = name
}

func (p *PidList) Remove(pid int) {
	_, ok := p.Pids[pid]
	if ok {
		delete(p.Pids, pid)
	}
}

func (p *PidList) Get(pid int) string {
	return p.Pids[pid]
}

func (p *PidList) IsHave(pid int) bool {
	_, ok := p.Pids[pid]
	return ok
}
